
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商城后台登录</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/static/admin/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/static/admin/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="/static/admin/css/amazeui.min.css" />
    <link rel="stylesheet" href="/static/admin/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="/static/admin/css/app.css">
    <script src="/static/admin/js/jquery.min.js"></script>

</head>

<body data-type="login">
    <script src="/static/admin/js/theme.js"></script>
    <div class="am-g tpl-g">
        <!-- 风格切换 -->
        <div class="tpl-skiner">
            <div class="tpl-skiner-toggle am-icon-cog">
            </div>
            <div class="tpl-skiner-content">
                <div class="tpl-skiner-content-title">
                    选择主题
                </div>
                <div class="tpl-skiner-content-bar">
                    <span class="skiner-color skiner-white" data-color="theme-white"></span>
                    <span class="skiner-color skiner-black" data-color="theme-black"></span>
                </div>
            </div>
        </div>
        <div class="tpl-login">
            <div class="tpl-login-content">
                <div class="tpl-login-logo">

                </div>


                <form class="am-form tpl-form-line-form" method="post" action="{% url 'dologin' %}">
                    {% csrf_token %}

                     <div class="am-form-group tishi1 " style="display:none;position:absolute;top:375px;">
                        <p style="color:red;">验证码错误,请重新输入</p>
                    </div>

                    <div class="am-form-group">
                        <input type="text" class="tpl-form-input" name="username" placeholder="请输入账号">
                    </div>
                    <div class="am-form-group">
                        <input type="password" class="tpl-form-input" name="password" placeholder="请输入密码">
                    </div>
                    <div class="am-form-group" style="position:relative;">
                        <input type="text" class="tpl-form-input"  name="vcode" placeholder="请输入验证码">
                        <div class ="tishi3" style="display:none;position:absolute;top:0px;left:330px;"><p style="color:red";>√</p>
                        </div>
                        <img src="{% url 'vcode' %}" style="position:absolute;top:0px;right:0px;" onclick="this.src='/admin/vcode?'+Math.random()">
                    </div>


                    <div class="am-form-group">
                        <button class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn">提交</button>
                    </div>

                </form>
            </div>
        </div>
    </div>

    <script src="/static/admin/js/amazeui.min.js"></script>
    <script src="/static/admin/js/app.js"></script>
    <script src="/static/admin/js/jquery-1.8.3.min.js"></script>

</body>
<script>

    //判断验证码是否正确:
    // 提示信息定位并且display为隐藏,给input框添加实时监控事件,在里面发送ajax请求,并根据值作出对应的判断
    // 相同:给出√  不同:提示错误  长度不满足:提示信息全部隐藏
    // 用change判断比较好,blur刷新页面就触发ajax
    // ajax 后台接收的函数:def vcodeajax(request): 返回session中保存的验证码
    var d = ''      //验证码值
    var a = ''      //输入的值
    $('input[ name="vcode" ]').bind('input porpertychange',function(){
        $.get('{% url 'vcodeajax' %}',function(data){
            d = data
        },'json');

        // 判断输入的值是否和验证码相等 且长度相等 判断
        var a = $('input[ name="vcode" ]').val();
        if(a != d && a.length == d.length){
            $('.tishi1').css("display","block");
        }
        // 输入长度小于验证码长度,不出现提示
        if (a.length<d.length){
            $('.tishi3').css("display","none");
            $('.tishi1').css("display","none");
        }
        // 输入正确,打勾√
        if (a == d){
            $('.tishi3').css("display","block");
        }
    });

</script>


</html>